package mcjunkin;
import java.io.*;

public class IgnoreFilter implements FilenameFilter{

	private String filterStr;
	private String regex[];

	/**
		Constructs a file name filter that treats str as a string for ignoring.
	*/

	public IgnoreFilter(String filterStr){
		this.filterStr = filterStr;
		regex = filterStr.split(",");
		for(int i=0; i < regex.length; i++)
			regex[i] = regex[i].replace("?", ".?").replace("*", ".*?");
	}

	/**
		Accept or deny a file name following rules of FileNameFilter interface.
	*/

	public boolean accept(File dir, String name){
		for(int i=0; i < regex.length;i++)
			if( name.matches(regex[i]) ) return false;
		return true;
	}

}
